package com.jyy.prefabricated.service;

import com.jyy.prefabricated.entity.CertificateCategory;
import com.jyy.prefabricated.exception.CustomException;
import com.jyy.prefabricated.mapper.CertificateCategoryMapper;
import com.jyy.prefabricated.mapper.CertificateCategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @version 1.0.0
 * @author: zjj
 */

@Service
public class CertificateCategoryService {

    @Autowired
    private CertificateCategoryMapper certificateCategoryMapper;

    /**
     * 新增
     * @param certificateCategory
     * @return
     */
    public Integer insert(CertificateCategory certificateCategory){
        certificateCategoryMapper.insert(certificateCategory);
        return certificateCategory.getId();
    }

    /**
     * 更新
     * @param certificateCategory
     * @return
     */
    public int update(CertificateCategory certificateCategory){
        if(certificateCategory.getId() == null){
            throw new CustomException("参数id不能为空");
        }
        return certificateCategoryMapper.updateByPrimaryKeySelective(certificateCategory);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    public int delete(Integer id){
        return certificateCategoryMapper.deleteByPrimaryKey(id);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    public CertificateCategory selectById(Integer id){
        return certificateCategoryMapper.selectByPrimaryKey(id);
    }

    /**
     * 查询列表
     * @return
     */
    public List<CertificateCategory> selectAll(){
        return certificateCategoryMapper.selectAll();
    }
}
